extends Panel
signal on_show(title : String)
signal on_failed()
signal on_pause()
signal on_hide()
@onready var title_label: Label = $VBoxContainer/Control/Title
@onready var try_onece: Button = $VBoxContainer/TryOnece
@onready var re_try: Button = $VBoxContainer/ReTry
@onready var back: Button = $VBoxContainer/Back

func _ready() -> void:
	on_show.connect(_on_show_event)
	on_failed.connect(_on_failed_event)
	on_pause.connect(_on_pause_event)
	on_hide.connect(_on_hide_event)
	try_onece.button_up.connect(_on_try_onece_button_up_event)
	re_try.button_up.connect(_on_re_try_button_up_event)
	back.button_up.connect(_on_back_button_up_event)

func _on_show_event(title : String) -> void :
	if title :
		title_label.text = title
		show()

func _on_pause_event() -> void :
	title_label.text = "已暂停"
	show()

func _on_failed_event() -> void :
	title_label.text = "失败"
	show()

func _on_hide_event() -> void :
	hide()

func _on_try_onece_button_up_event() -> void :
	get_tree().current_scene.try_count += 1
	hide()

func _on_re_try_button_up_event() -> void :
	GlobelFileRw.current_level_index -= 1
	get_tree().call_deferred("reload_current_scene")

func _on_back_button_up_event() -> void :
	GlobelFileRw.current_level_index = 0
	get_tree().call_deferred("change_scene_to_file","res://begin.tscn")
